# 添加成员（前提条件已经登录）
# 1. 点击导航栏【通讯录】按钮
# 2.点击【组织架构】
# 3. 点击添加成员按钮
# 4. 输入成员信息点击保存
# 5. 验证成员列表页面
import yaml
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait

import time



# 添加成员（前提条件已经登录）
# 1. 点击导航栏【通讯录】按钮
# 2.点击【组织架构】
# 3. 点击添加成员按钮
# 4. 输入重复标识的成员信息点击保存


def test_login():
  driver=webdriver.Chrome()
  driver.get("https://work.weixin.qq.com/")
  driver.find_element(By.XPATH,"//*[text()='企业登录']").click()
  time.sleep(30)
  cookie=driver.get_cookies()
  print(cookie)
  with open("cookie.yaml","w") as f:
    yaml.safe_dump(cookie,f)

def test_login_by_cookie():
  driver = webdriver.Chrome()
  driver.get("https://work.weixin.qq.com/")
  driver.find_element(By.XPATH, "//*[text()='企业登录']").click()
  with open("cookie.yaml","r",encoding="utf-8") as f:
    cookies=yaml.safe_load(f)
  print(f"读出来的cookie{cookies}")
  for cookie in cookies:
    try:
      driver.add_cookie(cookie)
    except Exception as e:
      print(e)
  driver.refresh()
  time.sleep(3)
#   #进行登录
#   driver.find_element()
#
#   #进入主页面
#   driver.find_element(By.XPATH,"//*[text()='通讯录']")
#   driver.find_element(By.XPATH,"//*[text()='组织架构']")
#   driver.find_element(By.CSS_SELECTOR,".member_colRight_cnt_operation .js_add_member")
#   driver.find_element(By.XPATH,"//*[@name='username']").send_keys("1111")
#   driver.find_element(By.XPATH,"//*[@name='acctid']").send_keys("1111")
#   driver.find_element(By.XPATH,"//*[@name='mobile']").send_keys("17706551963")
#   driver.find_element(By.XPATH,("//a[text()='保存']/[0]")[0]).click()
#   time.sleep(3)
#
#   member=driver.find_element(By.XPATH,"//*[text()='1111']")
#   assert member.text=="1111"
#
#   driver.find_element(By.XPATH,)

test_login()


 
